<?php

namespace App\Http\Middleware;

use Closure;

class LoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
       
        //检测cookie   如果username  cookie不为空 进入下一个中间件检测
        if (!empty($_COOKIE['username'])) {
            return $next($request);
        }else{
            //如果不存在则跳转
            return redirect('/login');
        }
    }
}
